import 'package:flutter/material.dart';
import 'package:kasax/commons/commons.dart';

class BottomSheetDemo extends StatefulWidget {
  const BottomSheetDemo({Key? key}) : super(key: key);

  @override
  _BottomSheetDemoState createState() => _BottomSheetDemoState();
}

class _BottomSheetDemoState extends State<BottomSheetDemo> {
  final _globalKey = GlobalKey<ScaffoldState>();
  String _selectValue = "Northing";

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        centerTitle: true,
        title: Text(
          "BottomSheetDemo",
        ),
      ),
      key: _globalKey,
      body: SafeArea(
        child: Container(
          child: Padding(
            padding: EdgeInsets.all(16),
            child: SingleChildScrollView(
              child: Container(
                child: Column(
                  children: [
                    Container(
                      child: Text(
                        "您选择的数据: $_selectValue",
                        style: TextStyle(fontSize: 18),
                      ),
                    ),
                    SizedBox(
                      height: 15,
                    ),
                    ListView(shrinkWrap: true, children: [
                      buildCircleButton("显示bottomSheet", () {
                        _showBottomSheet();
                      }),
                      buildCircleButton("显示对话框样式bottomSheet", () {
                        _showBottomSheet2();
                      })
                    ])
                  ],
                ),
              ),
            ),
          ),
        ),
      ),
    );
  }

  void _showBottomSheet() {
    _globalKey.currentState!.showBottomSheet((context) {
      return BottomAppBar(
        child: Container(
          height: 90,
          width: double.infinity,
          padding: EdgeInsets.all(10.0),
          child: Row(
            children: [
              Icon(Icons.pause_circle_outline),
              SizedBox(
                width: 10,
              ),
              Text("01:30 / 03:30"),
              Expanded(
                child: Text(
                  "Fix you - Coldplay",
                  textAlign: TextAlign.right,
                ),
              )
            ],
          ),
        ),
      );
    });
  }

  Future _showBottomSheet2() async {
    final option = await showModalBottomSheet(
        context: context,
        builder: (context) {
          return Column(
            children: [
              ListTile(
                title: Text("湖北"),
                onTap: () {
                  Navigator.pop(context, "湖北");
                },
              ),
              ListTile(
                title: Text("湖南"),
                onTap: () {
                  Navigator.pop(context, "湖南");
                },
              ),
              ListTile(
                title: Text("河北"),
                onTap: () {
                  Navigator.pop(context, "河北");
                },
              ),
            ],
          );
        });
    setState(() {
      _selectValue = option;
    });
  }
}
